package com.dayu.web.controller.basic;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.basic.domain.BasicClient;
import com.dayu.basic.service.IBasicClientService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

/**
 * 客户管理Controller
 *
 * @author HK
 * @date 2021-04-15
 */
@RestController
@RequestMapping("/basic/basicClient")
public class BasicClientController extends BaseController
{
    @Autowired
    private IBasicClientService basicClientService;

    /**
     * 查询客户管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BasicClient basicClient)
    {
        startPage();
        List<BasicClient> list = basicClientService.selectBasicClientList(basicClient);
        return getDataTable(list);
    }

    /**
     * 导出客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:basicClient:export')")
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BasicClient basicClient)
    {
        List<BasicClient> list = basicClientService.selectBasicClientList(basicClient);
        ExcelUtil<BasicClient> util = new ExcelUtil<BasicClient>(BasicClient.class);
        return util.exportExcel(list, "basicClient");
    }

    /**
     * 获取客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:basicClient:query')")
    @GetMapping(value = "/{clientId}")
    public AjaxResult getInfo(@PathVariable("clientId") Long clientId)
    {
        return AjaxResult.success(basicClientService.selectBasicClientById(clientId));
    }

    /**
     * 新增客户管理
     */
    @PreAuthorize("@ss.hasPermi('basic:basicClient:add')")
    @Log(title = "客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicClient basicClient)
    {
        return toAjax(basicClientService.insertBasicClient(basicClient));
    }

    /**
     * 修改客户管理
     */
    @PreAuthorize("@ss.hasPermi('basic:basicClient:edit')")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicClient basicClient)
    {
        return toAjax(basicClientService.updateBasicClient(basicClient));
    }

    /**
     * 删除客户管理
     */
    @PreAuthorize("@ss.hasPermi('basic:basicClient:remove')")
    @Log(title = "客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clientIds}")
    public AjaxResult remove(@PathVariable Long[] clientIds)
    {
        return toAjax(basicClientService.deleteBasicClientByIds(clientIds));
    }
}
